package com.taplinker.client.im.rpc;

import java.util.Date;

import com.taplinker.client.im.domain.ImDataCenter;
import com.taplinker.client.im.protocol.TapLinkerMessage;
import com.taplinker.client.im.rpc.body.Cmd006Rep;
import com.taplinker.client.im.rpc.body.Cmd006Req;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.util.json.JsonUtil;

public class Cmd006 extends SimpleSocketCommand<Cmd006Req> {
	
	public Cmd006(String conversationId,String content,String type) {
		body = new Cmd006Req();
		body.setContent(content);
		body.setConversationId(conversationId);
		body.setType(type);
	}
	
	private TapLinkerMessage message = null;
	public Cmd006(TapLinkerMessage message) {
		body = new Cmd006Req();
		body.setContent(message.getContent());
		body.setConversationId(message.getConversationId());
		body.setType(message.getType());
		this.message = message;
	}
	
	@Override
	public void yes(Result result) {
		super.yes(result);
		Cmd006Rep value = JsonUtil.jsonToObject(((IMMessageResponse) result.object).getMessage().getBody(), Cmd006Rep.class);
		message.setSendTime(new Date(value.getSendTime()));
		message.setMessageId(value.getMessageId());
		ImDataCenter.getInstance().noticeListener(message.getConversationId());
	}
	
	@Override
	protected String getCommand() {
		return "006";
	}
}
